#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e6+5;
ll t,n,a[N],co[N];
ll score(){
    ll res=0;
    for(int i=1;i<=n;i++){
        for(int j=i-1;j>=1;j--){
            if(co[i]==co[j]&&a[i]==a[j]){
                res+=a[i];
                break;
            }
        }
    }
    return res;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        ll ludan=(1<<n)-1,ans=-544544544;
        for(int i=0;i<=ludan;i++){
            ll heiren=ludan,p=n;
            while(heiren){
                co[p]=heiren%2;
                p--,heiren/=2;
            }
            ans=max(ans,score());
        }
        cout<<ans<<endl;
    }
    return 0;
}
